package com.atxiao.demo.config;

import com.atxiao.demo.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("lose").setViewName("powerlose");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] excludePathPatterns = getExcludeCommonPathPatterns();

        //拦截器生效
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(excludePathPatterns);
    }

    private String[] getExcludeCommonPathPatterns() {
        String[] urls = {
                "/login",
                "/getImage",
                "/",
                "/register",
                "/error",
                "/layer/**",
                "/layui/**",
                "/js/**",
                "/css/**",
                "/img/**"
        };
        return urls;
    }

}
